import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

// https://vite.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    // 暂时移除vueDevTools插件以解决__open-in-editor错误
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    },
  },
  server: {
    // 禁用自动打开编辑器功能
    hmr: {
      overlay: {
        runtimeErrors: (err) => !err.toString().includes('__open-in-editor')
      }
    },
    port: 5173 // 确保端口与electron配置一致
  },
  // 为electron应用配置构建选项
  base: './', // 使用相对路径，确保electron能正确加载
  build: {
    outDir: 'dist',
    assetsDir: 'assets',
    minify: 'terser',
    sourcemap: false,
    rollupOptions: {
      output: {
        // 确保静态资源路径正确
        manualChunks: undefined
      }
    }
  }
})
